import QtQuick 2.15
import QtQuick.Controls 2.15

// 测试程序无法获取Item控件属性，不能自动化测试.现在改为Button
Button {
    id:_button

    hoverEnabled:true
    font.pixelSize: 14

    property int nHeight: 32
    property int leftSpacing: 10
    property int rightSpacing: 10
    property int nWidth: 180
    property alias radius: _rectangleBackground.radius
    property int horizontalAlignment: Text.AlignHCenter
    property int verticalAlignment: Text.AlignVCenter

    property var colorBackgroundNormal: Gradient{
        GradientStop { position: 0.0; color: "#ffffff" }
        GradientStop { position: 1.0; color: "#ffffff" }
    }
    property var colorBackgroundDisable: Gradient{
        GradientStop { position: 0.0; color: "#0D000000" }
        GradientStop { position: 1.0; color: "#0D000000" }
    }
    property var colorBackgroundPress: Gradient{
        GradientStop { position: 0.0; color: "#3a65ff" }
        GradientStop { position: 1.0; color: "#4989fc" }
    }
    property var colorBackgroundHover: Gradient{
        GradientStop { position: 0.0; color: "#3a65ff" }
        GradientStop { position: 1.0; color: "#4989fc" }
    }

    property color colorBackgroundBorderNormal: "#D8E2EA"
    property color colorBackgroundBorderHover:"#2F53D3"
    property color colorBackgroundBorderPress:"#2F53D3"
    property color colorBackgroundBorderDisable:"#ffffff"

    property color colorTextNormal:"#FF313E55"
    property color colorTextHover:"#ffffff"
    property color colorTextPress:"#CCFFFFFF"
    property color colorTextDisable:"#4D26344C"

    implicitHeight:nHeight
    implicitWidth:{
        var nTmp = nWidth - leftSpacing - rightSpacing
        if(_text.contentWidth < nTmp){
            return nWidth
        }
        else{
            return _text.contentWidth + leftSpacing + rightSpacing
        }
    }

    function chooseStateParam(tmp1, tmp2, tmp3, tmp4){
        if(!_button.enabled){
            return tmp1
        }
        if(_button.pressed){
            return tmp2
        }
        if(_button.hovered){
            return tmp3
        }
        return tmp4
    }

    background:Rectangle{
        id:_rectangleBackground
        radius: 8
        gradient:_button.chooseStateParam(colorBackgroundDisable, colorBackgroundPress, colorBackgroundHover, colorBackgroundNormal)
        border.width:enabled?1:0
        border.color:_button.chooseStateParam(colorBackgroundBorderDisable, colorBackgroundBorderPress, colorBackgroundBorderHover, colorBackgroundBorderNormal)
    }

    contentItem:Text{
        id:_text
        font:_button.font
        text:_button.text
        color: _button.chooseStateParam(colorTextDisable, colorTextPress, colorTextHover, colorTextNormal)
        horizontalAlignment: _button.horizontalAlignment
        verticalAlignment: _button.verticalAlignment
    }
}
